import java.util.Stack;

public class MinStack {
    private Stack<Integer> stack;
    private Stack<Integer> minStack;

    public MinStack() {
        stack = new Stack<>();
        minStack = new Stack<>();

    }

    public void push(int val) {
        stack.push(val);
        // 第一次在最小栈中存储元素
        if(minStack.empty()){
            minStack.push(val);
        }else{
            if(val<=minStack.peek()){
                minStack.push(val);
            }
        }

    }

    public void pop() {
        // 栈为空 ，则不弹出元素
        if(stack.empty()){
            return;
        }
        int val = stack.pop();
        if(val == minStack.peek()){
            minStack.pop();
        }

    }
    // 获取栈顶元素，与最小栈无关
    public int top() {
        if(stack.empty()){
            return -1;
        }
        return stack.peek();

    }

    public int getMin() {
        return minStack.peek();

    }
}
